from django.shortcuts import render
from book.models import BookInfo
from django.http import HttpResponse
# Create your views here.
def create_book(request):
    book = BookInfo.objects.create(
        bookName = 'abc',
        pub_date='2000-1-1',
        readCount=10
    )

    return HttpResponse("create book")

def shop(request,city_id,shop_id):

    """
        http://127.0.0.1:8000/1101/1111/?order=readcount
    """
    query_params = request.GET
    # 得到get请求 order的值
    # <QueryDict: {'order': ['readcount']}>
    print(query_params)
    # order = query_params.get('order')
    # <QueryDict具有python字典的特性,还具有一键多值
    # print(order)  # readcount
    # order = query_params.get('order') # 只获取字典中key中的最后一个值
    # 如果想获取当前key中的所有的值,使用 query_params.getlist('order')
    # 一键一值用get
    # 一键多值用getlist
    order = query_params.getlist("order")
    """
        <QueryDict: {'order': ['readcount', 'comment'], 'page': ['1']}>
        ['readcount', 'comment']
    """
    print(order)

    return HttpResponse("create shop")

# 查询字符串
# http://ip:port/path/path/?key=value&key1=value1
# url 以 ？ 分隔
# 问号前面为请求路径
# 问号后面为查询字符串,也就是参数,类似于python中的字典key=value,多个key以&符号分隔
